home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_008 / src / hack.eat.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  355 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.eat.c version 1.0.1 - added morehungry() and FAINTED */
  3.  
  4. #include   "hack.h"
  5. char POISONOUS[] = "ADKSVabhks";
  6. extern char *nomovemsg;
  7. extern int (*afternmv)();
  8.  
  9. /* hunger texts used on bottom line (each 8 chars long) */
  10. #define SATIATED    0
  11. #define NOT_HUNGRY    1
  12. #define HUNGRY        2
  13. #define WEAK        3
  14. #define FAINTING    4
  15. #define FAINTED        5
  16. #define STARVED        6
  17.  
  18. char *hu_stat[] = {
  19.     "Satiated",
  20.     "        ",
  21.     "Hungry  ",
  22.     "Weak    ",
  23.     "Fainting",
  24.     "Fainted ",
  25.     "Starved "
  26. };
  27.  
  28. init_uhunger(){
  29.    u.uhunger = 900;
  30.    u.uhs = NOT_HUNGRY;
  31. }
  32.  
  33. struct { char *txt; int nut; } tintxts[] = {
  34.    {"It contains first quality peaches - what a surprise!",   40},
  35.    {"It contains salmon - not bad!",   60},
  36.    {"It contains apple juice - perhaps not what you hoped for.", 20},
  37.    {"It contains some nondescript substance, tasting awfully.", 500},
  38.    {"It contains rotten meat. You vomit.", -50},
  39.    {"It turns out to be empty.",   0}
  40. };
  41.  
  42. tinopen(){
  43. #define   TTSZ   (sizeof(tintxts)/sizeof(tintxts[0]))
  44. register int r = rn2(2*TTSZ);
  45.    if(r < TTSZ){
  46.        pline(tintxts[r].txt);
  47.        lesshungry(tintxts[r].nut);
  48.        if(r == 1)   /* SALMON */ {
  49.       Glib = rnd(15);
  50.       pline("Eating salmon made your fingers very slippery.");
  51.        }
  52.    } else {
  53.        pline("It contains spinach - this makes you feel like Popeye!");
  54.        lesshungry(600);
  55.        if(u.ustr < 118)
  56.       u.ustr += rnd( ((u.ustr < 17) ? 19 : 118) - u.ustr);
  57.        if(u.ustr > u.ustrmax) u.ustrmax = u.ustr;
  58.        flags.botl = 1;
  59.    }
  60. }
  61.  
  62. Meatdone(){
  63.    u.usym = '@';
  64.    prme();
  65. }
  66.  
  67. doeat(){
  68.    register struct obj *otmp;
  69.    register struct objclass *ftmp;
  70.    register int tmp;
  71.  
  72.    otmp = getobj("%", "eat");
  73.    if(!otmp) return(0);
  74.    if(otmp->otyp == TIN){
  75.       if(uwep && (uwep->otyp == AXE || uwep->otyp == DAGGER ||
  76.              uwep->otyp == CRYSKNIFE)){
  77.          pline("Using your %s you try to open the tin",
  78.             aobjnam(uwep, (char *) 0));
  79.          tmp = 3;
  80.       } else {
  81.          pline("It is not so easy to open this tin.");
  82.                 if(Glib) {
  83.                     pline("The tin slips out of your hands.");
  84.                     dropx(otmp);
  85.                     return(1);
  86.                 }
  87.                 if(otmp->quan > 1) {
  88.                     register struct obj *obj;
  89.                     extern struct obj *splitobj();
  90.  
  91.                     obj = splitobj(otmp, 1);
  92.                     if(otmp == uwep) setuwep(obj);
  93.                 }
  94.          tmp = 2 + rn2(1 + 500/((int)(u.ulevel + u.ustr)));
  95.       }
  96.       if(tmp > 50){
  97.          nomul(-50);
  98.          nomovemsg="You give up your attempt to open the tin.";
  99.       } else {
  100.          nomul(-tmp);
  101.          nomovemsg = "You succeed in opening the tin.";
  102.          afternmv = tinopen;
  103.          useup(otmp);
  104.       }
  105.       return(1);
  106.    }
  107.    ftmp = &objects[otmp->otyp];
  108.    if(otmp->otyp >= CORPSE && eatcorpse(otmp)) goto eatx;
  109.    if(!rn2(7) && otmp->otyp != FORTUNE_COOKIE) {
  110.       pline("Blecch!  Rotten food!");
  111.       if(!rn2(4)) {
  112.          pline("You feel rather light headed.");
  113.          Confusion += d(2,4);
  114.       } else if(!rn2(4)&& !Blind) {
  115.          pline("Everything suddenly goes dark.");
  116.          Blind = d(2,10);
  117.          seeoff(0);
  118.       } else if(!rn2(3)) {
  119.          if(Blind)
  120.            pline("The world spins and you slap against the floor.");
  121.          else
  122.            pline("The world spins and goes dark.");
  123.          nomul(-rnd(10));
  124.          nomovemsg = "You are conscious again.";
  125.       }
  126.       lesshungry(ftmp->nutrition / 4);
  127.    } else {
  128.       multi = -ftmp->oc_delay;
  129.       if(u.uhunger >= 1500) {
  130.          pline("You choke over your food.");
  131.          pline("You die...");
  132.          killer = ftmp->oc_name;
  133.          done("choked");
  134.       }
  135.       switch(otmp->otyp){
  136.       case FOOD_RATION:
  137.          if(u.uhunger <= 200)
  138.             pline("That food really hit the spot!");
  139.          else if(u.uhunger <= 700)
  140.             pline("That satiated your stomach!");
  141.          else {
  142.     pline("You're having a hard time getting all that food down.");
  143.             multi -= 2;
  144.          }
  145.          lesshungry(ftmp->nutrition);
  146.          if(multi < 0) nomovemsg = "You finished your meal.";
  147.          break;
  148.       case TRIPE_RATION:
  149.          pline("Yak - dog food!");
  150.          u.uexp++;
  151.          u.urexp += 4;
  152.          flags.botl = 1;
  153.             if(rn2(2)){
  154.                 pline("You vomit.");
  155.                 morehungry(20);
  156.          } else   lesshungry(ftmp->nutrition);
  157.          break;
  158.       default:
  159.          if(otmp->otyp >= CORPSE)
  160.          pline("That %s tasted terrible!",ftmp->oc_name);
  161.          else
  162.          pline("That %s was delicious!",ftmp->oc_name);
  163.          lesshungry(ftmp->nutrition);
  164. #ifdef QUEST
  165.          if(otmp->otyp == CARROT && !Blind){
  166.             u.uhorizon++;
  167.             setsee();
  168.             pline("Your vision improves.");
  169.          }
  170. #endif QUEST
  171.          if(otmp->otyp == FORTUNE_COOKIE) {
  172.            if(Blind) {
  173.              pline("This cookie has a scrap of paper inside!");
  174.              pline("What a pity, that you cannot read it!");
  175.            } else
  176.              outrumor();
  177.          }
  178.          break;
  179.       }
  180.    }
  181. eatx:
  182.    if(multi<0 && !nomovemsg){
  183.       static char msgbuf[BUFSZ];
  184.       (void) sprintf(msgbuf, "You finished eating the %s.",
  185.             ftmp->oc_name);
  186.       nomovemsg = msgbuf;
  187.    }
  188.    useup(otmp);
  189.    return(1);
  190. }
  191.  
  192. /* called in hack.main.c */
  193. gethungry(){
  194.    --u.uhunger;
  195.    if((Regeneration || Hunger) && moves%2) u.uhunger--;
  196.     newuhs(TRUE);
  197. }
  198.  
  199. /* called after vomiting and after performing feats of magic */
  200. morehungry(num) register int num; {
  201.     u.uhunger -= num;
  202.     newuhs(TRUE);
  203. }
  204.  
  205. /* called after eating something (and after drinking fruit juice) */
  206. lesshungry(num) register int num; {
  207.     u.uhunger += num;
  208.     newuhs(FALSE);
  209. }
  210.  
  211. unfaint(){
  212.     u.uhs = FAINTING;
  213.     flags.botl = 1;
  214. }
  215.  
  216. newuhs(incr) boolean incr; {
  217.     register int newhs, h = u.uhunger;
  218.  
  219.     newhs = (h > 1000) ? SATIATED :
  220.         (h > 150) ? NOT_HUNGRY :
  221.         (h > 50) ? HUNGRY :
  222.         (h > 0) ? WEAK : FAINTING;
  223.  
  224.     if(newhs == FAINTING) {
  225.         if(u.uhs == FAINTED)
  226.             newhs = FAINTED;
  227.         if(u.uhs <= WEAK || rn2(20-u.uhunger/10) >= 19) {
  228.             if(u.uhs != FAINTED && multi >= 0 /* %% */) {
  229.                 pline("You faint from lack of food.");
  230.                 nomul(-10+(u.uhunger/10));
  231.                 nomovemsg = "You regain consciousness.";
  232.                 afternmv = unfaint;
  233.                 newhs = FAINTED;
  234.             }
  235.         } else
  236.         if(u.uhunger < -(int)(200 + 25*u.ulevel)) {
  237.             u.uhs = STARVED;
  238.             flags.botl = 1;
  239.             bot();
  240.             pline("You die from starvation.");
  241.             done("starved");
  242.         }
  243.     }
  244.  
  245.     if(newhs != u.uhs) {
  246.         if(newhs >= WEAK && u.uhs < WEAK)
  247.             losestr(1);
  248.         else
  249.         if(newhs < WEAK && u.uhs >= WEAK && u.ustr < u.ustrmax)
  250.             losestr(-1);
  251.         switch(newhs){
  252.         case HUNGRY:
  253.             pline((!incr) ? "You only feel hungry now." :
  254.                   (u.uhunger < 145) ? "You feel hungry." :
  255.                 "You are beginning to feel hungry.");
  256.             break;
  257.         case WEAK:
  258.             pline((!incr) ? "You feel weak now." :
  259.                   (u.uhunger < 45) ? "You feel weak." :
  260.                 "You are beginning to feel weak.");
  261.             break;
  262.         }
  263.         u.uhs = newhs;
  264.         flags.botl = 1;
  265.    }
  266. }
  267.  
  268. /* returns 1 if some text was printed */
  269. eatcorpse(otmp) register struct obj *otmp; {
  270. register schar let = otmp->spe;
  271. register int tp = 0;
  272.    if(moves > otmp->age + 50 + rn2(100)) {
  273.       tp++;
  274.       pline("Ulch -- that meat was tainted!");
  275.       pline("You get very sick.");
  276.       Sick = 10 + rn2(10);
  277.       u.usick_cause = objects[otmp->otyp].oc_name;
  278.    } else if(index(POISONOUS, let) && rn2(5)){
  279.       tp++;
  280.       pline("Ecch -- that must have been poisonous!");
  281.       if(!Poison_resistance){
  282.          losehp(rnd(15), "poisonous corpse");
  283.          losestr(rnd(4));
  284.       } else
  285.          pline("You don't seem affected by the poison.");
  286.    } else if(index("ELNOPQRUuxz", let) && rn2(5)){
  287.       tp++;
  288.       pline("You feel sick.");
  289.       losehp(rnd(8), "cadaver");
  290.    }
  291.    switch(let) {
  292.    case 'L':
  293.    case 'N':
  294.    case 't':
  295.       Teleportation |= INTRINSIC;
  296.       break;
  297.    case 'W':
  298.       pluslvl();
  299.       break;
  300.    case 'n':
  301.       u.uhp = u.uhpmax;
  302.       flags.botl = 1;
  303.       /* fall into next case */
  304.    case '@':
  305.       pline("You cannibal! You will be sorry for this!");
  306.       /* not tp++; */
  307.       /* fall into next case */
  308.    case 'd':
  309.       Aggravate_monster |= INTRINSIC;
  310.       break;
  311.    case 'I':
  312.       See_invisible |= INTRINSIC;
  313.       if(!Invis) newsym(u.ux, u.uy);
  314.       Invis += 50;
  315.       /* fall into next case */
  316.    case 'y':
  317. #ifdef QUEST
  318.       u.uhorizon++;
  319. #endif QUEST
  320.       /* fall into next case */
  321.    case 'B':
  322.       Confusion = 50;
  323.       break;
  324.    case 'D':
  325.       Fire_resistance |= INTRINSIC;
  326.       break;
  327.    case 'E':
  328.       Telepat |= INTRINSIC;
  329.       break;
  330.    case 'F':
  331.    case 'Y':
  332.       Cold_resistance |= INTRINSIC;
  333.       break;
  334.    case 'k':
  335.    case 's':
  336.       Poison_resistance |= INTRINSIC;
  337.       break;
  338.    case 'c':
  339.       pline("You turn to stone.");
  340.       killer = "dead cockatrice";
  341.       done("died");
  342.    case 'M':
  343.      pline("You cannot resist the temptation to mimic a treasure chest.");
  344.      tp++;
  345.      nomul(-30);
  346.      afternmv = Meatdone;
  347.      nomovemsg = "You now again prefer mimicking a human.";
  348.      u.usym = '$';
  349.      prme();
  350.      break;
  351.    }
  352.    return(tp);
  353. }
  354.  
  355.